1 // Equipo Poncho, Carriel y Ruana
22 template <class T
> string
toStr(const T
&x
)
23 { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
)
25 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS
= 1e-9;
33 int cmp(double x
, double y
= 0, double tol
= EPS
) {
34 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
37 #define INPUT_FILE "compression"
39 const int MAXBASES
= 105, oo
= 1 << 28;
43 int bit
[20]; // bit[i] = index of term i in the document
45 int dp
[MAXBASES
][1 << 16];
50 for (int i
= 0; i
< 16; ++i
){
51 printf("%d", !!(x
& (1 << i
)));
57 bool canDelete(int base
) {
58 for (int j
= 0; j
< 16; ++j
) {
60 if (v
[j
] <= 1) return false;
66 bool noSolution(int doc
) {
67 for (int j
= 0; j
< 16; ++j
) {
69 if (v
[j
] == 0) return true;
76 for (int i
= 0; i
< 16; ++i
) {
80 for (int i
= 0; i
< B
; ++i
) {
81 if ((bases
[i
] | doc
) == doc
){
82 //printf("took base i = %d\n", i);
83 for (int j
= 0; j
< 16; ++j
){
84 if (bases
[i
] & (1 << j
)) {
91 for (int i
= 0; i
< B
; ++i
) {
92 if (canDelete(bases
[i
])) {
94 //printf("removed base i = %d\n", i);
95 for (int j
= 0; j
< 16; ++j
) {
96 if (bases
[i
] & (1 << j
)) {
103 if (noSolution(doc
)) {
111 bool popcount(int a
, int b
) {
112 return __builtin_popcount(a
) < __builtin_popcount(b
);
116 freopen(INPUT_FILE
".in", "r", stdin
);
117 while (cin
>> B
>> D
) {
118 if (B
== 0 and D
== 0) break;
119 for (int i
= 0; i
< B
; ++i
) {
124 int x
; cin
>> x
; x
--;
125 bases
[i
] |= (1 << x
);
127 //printf("base[i=%d] = %d\n", i, bases[i]);
129 sort(bases
, bases
+ B
, popcount
);
130 for (int j
= 0; j
< D
; ++j
) {
135 int x
; cin
>> x
; x
--;
138 //printf("doc = %d\n", doc);
140 if (j
+ 1 < D
) printf(" ");